package cn.tedu.charging.order.serializer;


import com.alibaba.fastjson2.JSON;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.nio.charset.StandardCharsets;

@Component
@Slf4j
public class MessageSerializer<T> {
    public byte[] serialize(T t){
        String json = JSON.toJSONString(t);
        return json.getBytes(StandardCharsets.UTF_8);
    }

    public T deserialize(byte[] bytes,Class<T> clazz){
        String json = new String(bytes,StandardCharsets.UTF_8);
        return JSON.parseObject(json,clazz);
    }
    public T deserizlize(String json,Class<T> clazz){
        return JSON.parseObject(json,clazz);
    }
}
